﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;

class Solution {
public:
    bool make(vector<int>& matchsticks, vector<int>& edges, int i, int len)
    {
        if (i == matchsticks.size()) return true;

        for (int k = 0; k < edges.size(); k++)
        {
            edges[k] += matchsticks[i];
            if (edges[k] <= len && make(matchsticks, edges, i + 1, len))
            {
                return true;
            }
            edges[k] -= matchsticks[i];
        }
        return false;
    }

    bool makesquare(vector<int>& matchsticks) {
        int total = accumulate(matchsticks.begin(), matchsticks.end(), 0);
        if (total % 4 != 0) return false;
        sort(matchsticks.begin(), matchsticks.end(), greater<int>());
        vector<int> edges(4, 0);
        return make(matchsticks, edges, 0, total / 4);
    }
};

int main()
{
    return 0;
}